<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="../../../../lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.useso.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="../../../../lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="../../../../css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="../../../../images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="../../../../images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="../../../../images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="../../../../images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Celery,Python,">










<meta name="description" content="关于异步的知识网上很多，这里就直接上代码，目前结合Flask这个Python框架实现后台任务的执行操作； 1.需要了解的知识点: 了解生产消费模型或者发布订阅模式来实现消息队列 了解异步、同步之间的差别  2.实现过程(1)目录结构├── LICENSE ├── README.md ├── app                     // Flask APP应用 │   ├── __init_">
<meta name="keywords" content="Celery,Python">
<meta property="og:type" content="article">
<meta property="og:title" content="如何使用Celery(芹菜)异步神器执行后台任务">
<meta property="og:url" content="http://demo_demo.gitee.io/2017/11/24/ru-he-shi-yongcelery-qin-cai-yi-bu-shen-qi-zhi-xin/index.html">
<meta property="og:site_name" content="运维人">
<meta property="og:description" content="关于异步的知识网上很多，这里就直接上代码，目前结合Flask这个Python框架实现后台任务的执行操作； 1.需要了解的知识点: 了解生产消费模型或者发布订阅模式来实现消息队列 了解异步、同步之间的差别  2.实现过程(1)目录结构├── LICENSE ├── README.md ├── app                     // Flask APP应用 │   ├── __init_">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115172368997.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115170661909.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115174358505.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115175046963.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115178118958.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115175573963.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115176602486.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115182402670.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115182685942.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115213514662.jpg">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115182945362.jpg">
<meta property="og:updated_time" content="2018-12-10T10:28:44.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="如何使用Celery(芹菜)异步神器执行后台任务">
<meta name="twitter:description" content="关于异步的知识网上很多，这里就直接上代码，目前结合Flask这个Python框架实现后台任务的执行操作； 1.需要了解的知识点: 了解生产消费模型或者发布订阅模式来实现消息队列 了解异步、同步之间的差别  2.实现过程(1)目录结构├── LICENSE ├── README.md ├── app                     // Flask APP应用 │   ├── __init_">
<meta name="twitter:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115172368997.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://demo_demo.gitee.io/2017/11/24/ru-he-shi-yongcelery-qin-cai-yi-bu-shen-qi-zhi-xin/">





  <title>如何使用Celery(芹菜)异步神器执行后台任务 | 运维人</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/guomaoqiu" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#FD6C6C; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">运维人</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">生命在于折腾</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://demo_demo.gitee.io">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OutMan">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维人">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">如何使用Celery(芹菜)异步神器执行后台任务</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-11-24T09:13:10+08:00">
                2017-11-24
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="../../../../categories/自动化运维/" itemprop="url" rel="index">
                    <span itemprop="name">自动化运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>关于异步的知识网上很多，这里就直接上代码，目前结合Flask这个Python框架实现后台任务的执行操作；</p>
<h3 id="1-需要了解的知识点"><a href="#1-需要了解的知识点" class="headerlink" title="1.需要了解的知识点:"></a>1.需要了解的知识点:</h3><ul>
<li>了解生产消费模型或者发布订阅模式来实现消息队列</li>
<li>了解异步、同步之间的差别</li>
</ul>
<h3 id="2-实现过程"><a href="#2-实现过程" class="headerlink" title="2.实现过程"></a>2.实现过程</h3><h4 id="1-目录结构"><a href="#1-目录结构" class="headerlink" title="(1)目录结构"></a>(1)目录结构</h4><pre><code>├── LICENSE
├── README.md
├── app                     // Flask APP应用
│   ├── __init__.py 
│   ├── auth
│   ├── email.py
│   ├── main
│   ├── models.py
│   ├── salt
│   ├── static
│   └── templates
├── config.py               // 通用配置
├── config.pyc
├── manager.py
├── migrations
│   ├── README
│   ├── alembic.ini
│   ├── env.py
│   └── versions
└── requirements.txt
</code></pre><h4 id="2-指定broker-backend-此处使用redis"><a href="#2-指定broker-backend-此处使用redis" class="headerlink" title="(2)指定broker/backend(此处使用redis)"></a>(2)指定broker/backend(此处使用redis)</h4><p>vim app/__init__.py</p>
<pre><code>// 部分代码
from celery import Celery

app = Flask(__name__)

broker = &apos;redis://127.0.0.1:6379&apos;
backend = &apos;redis://127.0.0.1:6379/0&apos;

celery = Celery(app.name, broker=broker, backend=backend)

// 部分代码
</code></pre><p>以上引入了Celery,指定了Celery的生产消费端都为我们的redis</p>
<h4 id="3-这里我将任务写到了视图函数中"><a href="#3-这里我将任务写到了视图函数中" class="headerlink" title="(3)这里我将任务写到了视图函数中"></a>(3)这里我将任务写到了视图函数中</h4><p>vim app/main/views.py</p>
<ul>
<li><p>(1 创建一个任务函数, 并且将这个任务绑定上了celery的标记</p>
<h3 id="部分代码"><a href="#部分代码" class="headerlink" title="部分代码"></a>部分代码</h3><p>@celery.task(bind=True)<br>def update_cbt_resource(self):</p>
<pre><code>&apos;&apos;&apos;
@summary: 创建一个需要后台去执行的任务，我这里只是举个栗子
&apos;&apos;&apos;
result=commands.getoutput(&quot;sleep 20 &amp;&amp; echo &apos;ok&apos;&quot;)
return result
</code></pre></li>
</ul>
<ul>
<li><p>(2 创建一个执行任务请求函数</p>
<h3 id="部分代码-1"><a href="#部分代码-1" class="headerlink" title="部分代码"></a>部分代码</h3><p>@main.route(‘/execute_task/&lt;update_env&gt;’, methods=[‘GET’, ‘POST’])<br>def execute_task(update_env):</p>
<pre><code>&quot;&quot;&quot;
@summary: 请求函数入口
&quot;&quot;&quot;
# 这里用最笨的办法执行了在我们web中点击执行任务之前去检查celery这个服务是否存在，如果不存在会提示用户    
result = commands.getoutput(&quot;ps -ef | grep celery | grep -v grep&quot;)
if not result:
    return jsonify({&quot;result&quot;:False,&quot;message&quot;:u&apos;未发现Celery进程，请检查该服务是否正常启动&apos;})

 # 将前面写的任务函数直接调用apply_async属性
task = update_cbt_resource.apply_async()

 # 这里就可以获取到这个任务一开始执行就返回的一些属性
 # 比如任务ID, 任务状态
data = {
    &quot;task_id&quot;: task.id,
    &quot;task_status&quot;: task.status
}

# 将以上的信息作为这请求函数的返回
result = {&quot;result&quot;:True,&quot;data&quot;:data,&quot;message&quot;:u&apos;执行开始&apos;}
return jsonify(result)
</code></pre></li>
</ul>
<ul>
<li>(3 创建一个任务状态查询的函数</li>
</ul>
<p>一般任务触发之后我们想要知道这个任务的执行状态，是处于哪个阶段的，各个状态已经在官网详细说明了；有兴趣的直接看<a href="http://docs.celeryproject.org/en/master/userguide/tasks.html?highlight=built-in-states" target="_blank" rel="noopener">官网</a></p>
<pre><code>### 部分的代码
@main.route(&apos;/task_result&apos;, methods=[&apos;GET&apos;])
@login_required
def task_result():
    &apos;&apos;&apos;
    @summary: 任务的状态是通过task_id来获取,在触发了任务之后,通过前端js轮询请求这个函数，就可以得到该任务的当前执行状态
    &apos;&apos;&apos;
    # 点击执行按钮前端会传一个task_id到后端,这里使用form的方式获取到task_id
    task_id = json.loads(request.form.get(&apos;data&apos;))[&apos;task_id&apos;]

    # AsyncResult，它的作用是被用来检查任务状态，等待任务执行完毕或获取任务结果，如果任务失败，它会返回异常信息或者调用栈。
    the_task = update_cbt_resource.AsyncResult(task_id)

    print(&quot;任务：{0} 当前的 state 为：{1}&quot;.format(task_id, the_task.state))

     # 执the_task.state
    if  the_task.state  == &apos;PROGRESS&apos;:
        print the_task.info.get(&apos;i&apos;, 0)
        result = {&apos;state&apos;: &apos;progress&apos;,&quot;result_data&quot;:the_task.result}
    elif  the_task.state  == &apos;SUCCESS&apos;:
        result = {&apos;state&apos;: &quot;success&quot;, &quot;result_data&quot;:the_task.result}
    elif  the_task.state  == &apos;PENDING&apos;:
        result = {&apos;state&apos;: &apos;waitting&apos;,&quot;result_data&quot;:the_task.result}
    elif  the_task.state  == &apos;REVOKED&apos;:
        result = { &apos;state&apos;: &apos;revoke&apos;, &quot;result_data&quot;:the_task.result}
        print the_task.result
    else:
        result = {&apos;state&apos;: the_task.state,&apos;progress&apos;:0,&quot;result_data&quot;:the_task.result}
    return jsonify(result)
</code></pre><ul>
<li>(4 尝试在前端页面点击执行任务<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115172368997.jpg" alt="">￼<br>Oops! 这就是上面进行celery进程判断之后得到的提示信息，那下面就把celery启动起来吧<figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">    </span><br><span class="line">*   (<span class="number">5</span> 启动Celey服务</span><br><span class="line">    </span><br><span class="line"></span><br><span class="line">    celery worker -A manager.celery -l debug</span><br><span class="line">    ### 我这里是本地使用的virtualenv环境</span><br></pre></td></tr></table></figure></li>
</ul>
<p><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115170661909.jpg" alt="">￼<br>ok, 现在启动了celery服务之后我们在前台执行一下:<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115174358505.jpg" alt="">￼<br>通过点击执行后我们看日志：<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115175046963.jpg" alt="">￼</p>
<p>任务执行完毕了；<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115178118958.jpg" alt="">￼</p>
<p>再看看Flask的日志,这就是通过js轮询请求这个task_resul函数的结果<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115175573963.jpg" alt="">￼<br>再来看看redis中的内容,这就将结果保存到了backend中<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115176602486.jpg" alt="">￼</p>
<h4 id="4-如何撤销一个任务呢"><a href="#4-如何撤销一个任务呢" class="headerlink" title="(4)如何撤销一个任务呢?"></a>(4)如何撤销一个任务呢?</h4><p>还是通过task_id来实现。视图函数中编写一个任务的函数</p>
<pre><code>### 部分代码
@main.route(&apos;/cancel_task/&apos;, methods=[&apos;GET&apos;, &apos;POST&apos;])
@login_required
def cancel_task():
     # 通过前端的取消按钮来获取到这个任务的id
    task_id = json.loads(request.form.get(&apos;data&apos;))[&apos;task_id&apos;]
    try:
        celery.control.revoke(task_id, terminate=True, signal=&apos;SIGKILL&apos;)
        return Response(json.dumps({&apos;result&apos;:True,&quot;message&quot;: &quot;取消任务完成&quot; }))
    except Exception,e:
        return Response(json.dumps({&apos;result&apos;: True, &quot;message&quot;: u&apos;取消任务失败.{0}&apos;.format(e)}))
</code></pre><p>执行过程如下:<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115182402670.jpg" alt="">￼<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115182685942.jpg" alt="">￼<br><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115213514662.jpg" alt="">￼</p>
<p><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2017/11/15115182945362.jpg" alt="">￼<br>需要注意的是,在上面视图函数中的这段代码其实有也可以撤销</p>
<pre><code>task = update_cbt_resource.apply_async()
task.revoke() 
</code></pre><p>但是这种方式只是撤销，如果任务已经在执行撤销则无效;所以我这里可以使用下面的方法来撤销</p>
<pre><code># 通过task_id撤销
celery.control.revoke(task_id)
# 撤销正在执行的任务，默认使用TERM信号
celery.control.revoke(task_id, terminate=True)
# 撤销正在执行的任务，默认使用KILL信号
celery.control.revoke(task_id, terminate=True, signal=&apos;SIGKILL&apos;)
#在官网文档中也可以将多个task_id组成列表形式然后同时撤销多个任务
celery.control.revoke([task_id1,task_id2,task_id3,task_id4.......])
</code></pre><h4 id="ok，以上就是Celery-的基本使用。"><a href="#ok，以上就是Celery-的基本使用。" class="headerlink" title="ok，以上就是Celery 的基本使用。"></a>ok，以上就是Celery 的基本使用。</h4>
      
    </div>
    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>


  
</div>
    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="../../../../tags/Celery/" rel="tag"># Celery</a>
          
            <a href="../../../../tags/Python/" rel="tag"># Python</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="../../../06/04/redis-ji-qun-xiang-xi-da-jian-zhi-nan/" rel="next" title="Redis集群详细搭建指南">
                <i class="fa fa-chevron-left"></i> Redis集群详细搭建指南
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="../../../../2018/03/08/ru-he-li-yonggit-webhook-jin-xing-bu-shu/" rel="prev" title="如何利用Git Webhook 进行部署">
                如何利用Git Webhook 进行部署 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png" alt="OutMan">
            
              <p class="site-author-name" itemprop="name">OutMan</p>
              <p class="site-description motion-element" itemprop="description">😊</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="../../../../archives/">
              
                  <span class="site-state-item-count">79</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="../../../../categories/index.html">
                  <span class="site-state-item-count">22</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="../../../../tags/index.html">
                  <span class="site-state-item-count">46</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/guomaoqiu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i></a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:guomaoqiu@google.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i></a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-需要了解的知识点"><span class="nav-number">1.</span> <span class="nav-text">1.需要了解的知识点:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-实现过程"><span class="nav-number">2.</span> <span class="nav-text">2.实现过程</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-目录结构"><span class="nav-number">2.1.</span> <span class="nav-text">(1)目录结构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-指定broker-backend-此处使用redis"><span class="nav-number">2.2.</span> <span class="nav-text">(2)指定broker/backend(此处使用redis)</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-这里我将任务写到了视图函数中"><span class="nav-number">2.3.</span> <span class="nav-text">(3)这里我将任务写到了视图函数中</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#部分代码"><span class="nav-number">3.</span> <span class="nav-text">部分代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#部分代码-1"><span class="nav-number">4.</span> <span class="nav-text">部分代码</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-如何撤销一个任务呢"><span class="nav-number">4.1.</span> <span class="nav-text">(4)如何撤销一个任务呢?</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ok，以上就是Celery-的基本使用。"><span class="nav-number">4.2.</span> <span class="nav-text">ok，以上就是Celery 的基本使用。</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OutMan</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="../../../../lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="../../../../js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="../../../../js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="../../../../js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="../../../../js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="../../../../js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
